<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class ContactCSMEModel extends JLModelBase {

    /**
     * Funcion que retorna Contact
     * @Retorna array
     */
    public function getContactById($id) {
        $_true = null;

        $sql = "SELECT 
              `int_id_contact_csme`,
              `var_cont_nom`,
              `var_cont_status`,
              `var_cont_tel`,
              `var_cont_email`,
              `int_id_state`
            FROM 
              `tbl_contact_csme`
            WHERE `int_id_contact_csme` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
            $_true = $_true[0];
        }

        return $_true;
    }

    /**
     * Actualiza Contact
     * @Retorna bool
     */
    public function updateContact($id, $var_cont_nom, $var_cont_tel, $var_cont_status, $var_cont_email, $int_id_state) {
        $_true = false;

        $sql = "UPDATE 
              `tbl_contact_csme`  
            SET
              `var_cont_nom` = " . $this->DB->Quote($var_cont_nom) . ",
              `var_cont_status` = " . $this->DB->Quote($var_cont_status) . ",
              `var_cont_tel` = " . $this->DB->Quote($var_cont_tel) . ",
              `var_cont_email` = " . $this->DB->Quote($var_cont_email) . ",
              `int_id_state` = " . $this->DB->Quote($int_id_state) . "
            WHERE 
              `int_id_contact_csme` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Inserta Contact
     * @Retorna bool
     */
    public function insertContact($var_cont_nom, $var_cont_tel, $var_cont_status, $var_cont_email, $int_id_state) {
        $_true = false;

        $sql = "INSERT INTO 
              `tbl_contact_csme`
            (
              `var_cont_nom`,
              `var_cont_status`,
              `var_cont_tel`,
              `var_cont_email`,
              `int_id_state`
            ) 
            VALUE(
              " . $this->DB->Quote($var_cont_nom) . ",
              " . $this->DB->Quote($var_cont_status) . ",
              " . $this->DB->Quote($var_cont_tel) . ",
              " . $this->DB->Quote($var_cont_email) . ",
              " . $this->DB->Quote($int_id_state) . ")";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Elimina Contact
     * @Retorna bool
     */
    public function deleteContact($id) {
        $_true = false;

        $sql = "DELETE FROM 
              `tbl_contact_csme` 
            WHERE 
              `int_id_contact_csme` = " . $this->DB->Quote($id) . " AND `int_id_state` <> 1";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

}

?>